package com.westa.smallshop.user;


import android.support.annotation.NonNull;

import com.westa.smallshop.data.GoodsItem;
import com.westa.smallshop.data.source.UserDataSource;
import com.westa.smallshop.data.source.remote.BaseDataSource;

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;

public class UserInfoPresenter implements UserInfoContract.Presenter {

    @NonNull
    private UserInfoContract.View mView;

    @NonNull
    private UserDataSource mUserDataSource;

    public UserInfoPresenter(@NonNull UserInfoContract.View view,
                             @NonNull UserDataSource userDataSource){
        mUserDataSource = checkNotNull(userDataSource);
        mView = checkNotNull(view);

        mView.setPresenter(this);
    }
    @Override
    public void start() {
    }

    @Override
    public void destroy() {

    }

    @Override
    public void refreshData() {
        mUserDataSource.getGoodsList(new BaseDataSource.LoadListCallBack<GoodsItem>() {
            @Override
            public void onRefreshDataSuccessful(List<GoodsItem> data) {
                mView.setRefreshing(false);
                mView.refreshData(data);
            }

            @Override
            public void onLoadMoreDataSuccessful(List<GoodsItem> data) {

            }

            @Override
            public void onLoadDataFailed() {
                mView.setRefreshing(false);
            }
        });
    }
}
